//
//  ZDProfileViewController.swift
//  1026SwiftSinaWeiBo
//
//  Created by Apple on 15/10/26.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit
import SDWebImage

class ZDProfileViewController: ZDBaseTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")

        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "清除缓存", style: UIBarButtonItemStyle.Done, target: self, action: "clear")
    }

    func clear() {
    
        SDImageCache.sharedImageCache().clearDisk()
        
        tableView.reloadData()
    }

}


extension ZDProfileViewController {

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 1
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCellWithIdentifier("cell")!
        
        let size = Double(SDImageCache.sharedImageCache().getSize()) / 1000.0 / 1000.0
        
        //设置2位小数
        let newSize = String(format: "%.2", [size])
        
        cell.textLabel?.text = "混存\(newSize) M"
        
        return cell
    }
}